const cheerio = require("cheerio");
function homepage(content) {
    const $ = cheerio.load(content);
    const menu = [];
    var liEles = $("ul.myui-header__menu li");
    for (let index = 0; index < liEles.length; index++) {
        const liEle = $(liEles[index]);
        var active = liEle.hasClass("active");
        const aEle = liEle.find("a");
        var title = aEle.text().trim();
        var href = aEle.attr("href");
        menu.push({ active, title, href, hrefType: "videoList" });
    }
    const children = [];
    var divEles = $('div.myui-panel.myui-panel-bg.clearfix');
    for (let index = 0; index < divEles.length; index++) {
        const divEle = $(divEles[index]);
        var title1 = divEle.find('div.myui-panel__head h3.title').text().trim();
        var liEles = divEle.find('ul.myui-vodlist li');
        var items = [];
        for (let index = 0; index < liEles.length; index++) {
            const liEle = $(liEles[index]);
            const aEle = liEle.find("a.vodlist__thumb");
            var title = aEle.attr('title');
            var href = aEle.attr("href");
            var imagePath = aEle.attr('data-original');
            var hint = aEle.text().trim();
            var synopsis = liEle.find('p').text().trim();
            // voddetail/2907.html
            // vodplay/2907-1-1.html
            items.push({title, href,hrefType: "videoInfo",imagePath,hint,synopsis });
        }
        children.push({title:title1,children:items});
    }
}
function videoList(content) {
    const $ = cheerio.load(content);
    return {};
}

function videoPlayPath(content) {
    const $ = cheerio.load(content);
    return {};
}

function videoInfo(content) {
    const $ = cheerio.load(content);
    return {};
}

function searchVideo(content) {
    const $ = cheerio.load(content);
    const list = [];
    if (list.length == 0) throw Error("未搜到相关数据");
    return {};
}

function parsePage($) {
    $("");
}

module.exports = { videoList, videoInfo, videoPlayPath, searchVideo };
